Why React Strict Mode breaks your app - on purpose

Поделиться
HTML-код
  • Опубликовано: 28 сен 2024
  • Check out my premium video courses on Build UI:
    buildui.com

Комментарии • 30

  • @deiminator2
    @deiminator2 Год назад +65

    Bro I'm an experienced react dev so I already know most of the stuff you talk about. But you are probably the best coding RUclipsr on the platform, no yelling mild takes, not pushing an agenda, just clean, precise and interesting content. Keep it up!

    • @robbyoconnor
      @robbyoconnor Год назад +4

      I've met him in person... he's like this in person as well. Very down to earth

    • @samselikoff
      @samselikoff  Год назад +1

      Really appreciate this message 😊 👊

    • @UncleDavid
      @UncleDavid Год назад

      he has baraka in him lol

    • @Developer888
      @Developer888 Год назад

      As a react rookie, I appreciate the breakdown

  • @wfl-junior
    @wfl-junior Год назад +5

    That probably explains why I get the api calls with react query running twice on mount, good thing I started using the signal to abort the request on cleanup.
    I was aware of React's strict mode, but never understood it correctly, this video made it very clear, thank you!
    And I think strict mode is a must, very useful.

  • @HaraldLønsethagen-c7t
    @HaraldLønsethagen-c7t Месяц назад

    Love the video and your production style! Learned some good stuff here. (It could have been slightly higher pace or shorter, but otherwise really good!)

  • @simonswiss
    @simonswiss Год назад +1

    Sheesh this was really great! I knew about the "cleanup" return function in useEffect, but I have probably done that mistake 100 times in my apps, and never noticed 😅 Also - the backlight doubling as practical light in the background is 🧑‍🍳😘

  • @justine_chang39
    @justine_chang39 Год назад

    React Strict Mode white background blinded me, now I sing about just calling someone and saying I love you.

  • @andrewsidorchuk9289
    @andrewsidorchuk9289 Год назад

    Awesome explanation! Thanks man

  • @clear_out6474
    @clear_out6474 Год назад

    Why was this in my recommended? lmao im not close to be a programer xD cool explanation tho 👍

  • @yairvsync
    @yairvsync Год назад

    React Strict mode simple replaces a "maybe" bug with a "certain" but which noob/blind devs might miss
    and therefore introduce bugs into the system. Strict mode is a big no-no for me, for years. It's catastrophic.

  • @codingwithdidem
    @codingwithdidem Год назад +3

    Thanks! I often misunderstand the whole concept of strict mode. One time I was fetching the data multiple times and end up wasting 1 day only to find out it was happening bcz of the strict mode tho:)

  • @pelaoinfo
    @pelaoinfo 7 месяцев назад

    this is completely broken when you try to use refs

  • @flying_salt
    @flying_salt 10 месяцев назад

    Thanks a lot

  • @cdes
    @cdes Год назад +2

    I’ve always enjoyed your streams while you’re working on Mirage. When I get a notification for a new video from you, I get really excited, and you never disappoint. Keep on going! Your videos are insanely good. Quality content, superb delivery. Only a if you make them more often.

  • @StingSting844
    @StingSting844 Год назад +1

    bro why are you so good in teaching?! Its abnormal that I'm able to grasp every single word that comes out of your mouth!

  • @mmmike3426
    @mmmike3426 Год назад

    The production value of this video is so high. Damn man, even down to that exceptionally groomed beard 😂 You're basically the Wenger of dev content!

  • @HarshilParmar-f6d
    @HarshilParmar-f6d Год назад

    The way you talk is really awesome man!! And I never heard about chaos monkey. Thanks

  • @_va3y
    @_va3y Год назад +1

    Your vim chops are smooth..
    I’ve also got into it last month

    • @pablozuta2402
      @pablozuta2402 Год назад

      That's vscode bro

    • @tefkah
      @tefkah Год назад +4

      @@pablozuta2402 yeah but he's clearly using vim bindings

    • @samselikoff
      @samselikoff  Год назад +1

      Best investment you’ll ever make!

  • @HeyNoah
    @HeyNoah Год назад

    This is great! Thank you so much for this breakdown! 🙏

  • @ThomazMartinez
    @ThomazMartinez Год назад

    For me most of the time is i dont get errors with strict mode in dev but when in Prod then i start getting issues

  • @typescripter
    @typescripter Год назад

    Thx

  • @kevinbatdorf
    @kevinbatdorf Год назад

    The proper way to implement this is to instead use setTimeout and add count as a dependency, so that when count is updated it restarts the timeout. setInterval should never be used as it does not guarantee execution if the inner function takes longer than the interval. (there are other issues with setInterval as well - can google it for more info)

    • @kevinbatdorf
      @kevinbatdorf Год назад

      Also, I'm not being critical of your content. I know it wasn't the point of this video. Keep it coming!

    • @samselikoff
      @samselikoff  Год назад

      The logic is "increase the count by 1 every second" - that's an interval. You don't want to use count as a dependency to achieve this behavior for two reasons: first, it's literally not a dependency when using the function version of setState, and second (and more importantly), count could change for reasons other than the interval increasing it. (If you wanted different logic based on count changing for other reasons, that would also be achievable, but it's a different requirement.)
      I'm not sure I understand your point about "the inner function taking longer than the interval". The inner function here is just a call to setState and is not asynchronous code, and it would be the same if it were in a timeout. You can absolutely use setInterval in React applications. There do exist libraries like useInterval which offer more functionality, but they ultimately are more sophisticated wrappers around setInterval.
      (And no criticism taken, I welcome the questions!)